/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sp.validasi;

import java.awt.Color;
import java.util.ArrayList;
import sp.component.TextField;
import sp.form.Hal7;
import sp.model.B1;
import sp.model.B5;
import sp.model.Error;
import sp.model.Sisipan;

/**
 *
 * @author Thosan Girisona S
 */
public class ValidasiB5Sisipan {

    ArrayList<TextField> arr;
    B1 b1;
    B5 b5;
    Sisipan ssp;
    Hal7 hal7;
    TextField dummy;
    private ArrayList<Error> b7listerr;

    public ValidasiB5Sisipan(B1 b1, B5 b5, Sisipan ssp, Hal7 b7view) {
        this.b1 = b1;
        this.b5 = b5;
        this.ssp = ssp;
        this.hal7 = b7view;
    }

    public ArrayList<Error> cek() {
        b7listerr = new ArrayList<>();
        cekDurasi();
        cekPertanyaan1a();
        cekPertanyaan2();
        return b7listerr;
    }

    private TextField toDisable(TextField tx) {
        tx.setText("");
        tx.setEnabled(false);
        return tx;
    }
    
    private TextField getError(TextField tx) {
        tx.setBackground(Color.red);
        return tx;
    }

    private void cekPertanyaan1a() {
        if(hal7.getPertanyaan1a().getText().equals("2")){
            dummy = toDisable(hal7.getPertanyaan1b());
            hal7.setPertanyaan1b(dummy);
        }
    }

    private void cekPertanyaan2() {
        if(hal7.getPertanyaan2().getText().equals("2")){
            dummy = toDisable(hal7.getPertanyaan3a());
            hal7.setPertanyaan1b(dummy);
            dummy = toDisable(hal7.getPertanyaan3b());
            hal7.setPertanyaan1b(dummy);
        }
    }

    private void cekDurasi() {
        if(Integer.valueOf(b1.getTimestamp())<0){
            dummy = getError(hal7.getDurasi());
            hal7.setDurasi(dummy);
            b7listerr.add(b7listerr.size(), new Error("Durasi", "Kesalahan Waktu Durasi", 7));
        }
    }
}
